package org.example.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.example.entity.RechargePackages;

import java.util.List;

@Mapper
public interface RechargePackagesMapper extends BaseMapper<RechargePackages> {
    //查询所有套餐
    @Select("SELECT\n" +
            "amount_cent,\n" +
            "created_time,\n" +
            "id,\n" +
            "is_hot,\n" +
            "NAME,\n" +
            "points,\n" +
            "amount_cent / 100 AS price_yuan,\n" +
            "\tSTATUS,\n" +
            "\tupdated_time\n" +
            "FROM\n" +
            "recharge_packages\n" +
            "ORDER BY\n" +
            "amount_cent ASC")
    List<RechargePackages>  getAllRechargePackages();
    //修改套餐
    @Update("UPDATE recharge_packages\n" +
            "        SET \n" +
            "            name = #{name},\n" +
            "            amount_cent = #{amountCent},\n" +
            "            points = #{points},\n" +
            "            is_hot = #{isHot},\n" +
            "            status = #{status},\n" +
            "            updated_time = NOW()\n" +
            "        WHERE \n" +
            "            id = #{id}")
    int updateRechargePackage(RechargePackages rechargePackage);
}
